package step1;

public class ThirdPartyhunauClass implements ThirdPartyhunauLib{

    private void connectToServer(String server) {
        System.out.print("Connecting to " + server + "... ");
        experienceNetworkLatency();
        System.out.print("Connected!" + "\n");
    }
    @Override
    public Video getVideo(String videoId) {
        connectToServer("https://www.hunau.edu.cn/" + videoId);
        return getSomeVideo(videoId);
    }
    //随机产生min-max间的整数
    private int random(int min, int max) {
        return min + (int) (Math.random() * ((max - min) + 1));
    }
    //模拟网络访问的时间间隔
    private void experienceNetworkLatency() {
        int randomLatency = random(5, 10);
        for (int i = 0; i < randomLatency; i++) {
            try {
                Thread.sleep(100);
            } catch (InterruptedException ex) {
                ex.printStackTrace();
            }
        }
    }

    private Video getSomeVideo(String videoId) {
        System.out.print("Downloading video... ");
        experienceNetworkLatency();
        Video video = new Video(videoId, "Some video title");
        System.out.print("Done!" + "\n");
        return video;
    }
}
